﻿<Framework:PageViewBase x:Class="DeSleeper.Client.WakeUp.WakeUpView" 
    x:TypeArguments="WakeUp:WakeUpViewModel"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:WakeUp="clr-namespace:DeSleeper.Client.WakeUp"
    xmlns:Framework="clr-namespace:DeSleeper.Client.Framework;assembly=DeSleeper.Client.Framework"
    Title="Send Wake Up" 
    Name="_this"
    VerticalAlignment="Stretch" HorizontalAlignment="Stretch"
    DataContext="{Binding RelativeSource={RelativeSource Self}}"
    Height="Auto" Width="Auto">
    <Page.Resources>        
        <DataTemplate DataType="{x:Type WakeUp:TargetComputer}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="Labels"/>
                    <ColumnDefinition Width="*"/>
                    <ColumnDefinition SharedSizeGroup="Buttons"/>
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Label Grid.Column="0" Name="descriptionLabel" Target="{Binding ElementName=description}">
                   _Description:
                </Label>
                <TextBox Grid.Column="1" Name="description" Text="{Binding Path=Description}" />
                <Button 
                    Grid.Column="2" 
                    Name="wakeUpButton" 
                    VerticalAlignment="Center"
                    Command="{Binding ElementName=_this, Path=ViewModel.WakeUpCommand}" 
                    CommandParameter="{Binding}">
                    Wake Up Now
                </Button>

                <ContentPresenter Grid.Row="1" Grid.ColumnSpan="3" Content="{Binding Path=Destination, Mode=OneWay}"/>
                <ContentPresenter Grid.Row="2" Grid.ColumnSpan="3" Content="{Binding Path=WakeUpMethod, Mode=OneWay}"/>
            </Grid>
        </DataTemplate>
        
        <DataTemplate DataType="{x:Type WakeUp:MacAddressWakeUpMethod}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="Labels"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Name="macAdressLabel" Target="{Binding ElementName=macAddress}">
                    _MAC Address:
                </Label>
                <TextBox Grid.Column="1" Name="macAddress" Text="{Binding Path=Target.(WakeUp:MacAddressWakeUpMethod.MacAddress)}"/>
            </Grid>
        </DataTemplate>

        <DataTemplate DataType="{x:Type WakeUp:HostNameWakeUpMethod}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="Labels"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Name="hostNameLabel" Target="{Binding ElementName=hostName}">
                   _Host:
                </Label>
                <TextBox Grid.Column="1" Name="hostName" Text="{Binding Path=Target.(WakeUp:HostNameWakeUpMethod.HostName)}"/>
            </Grid>
        </DataTemplate>

        <!-- No UI necessary. -->
        <DataTemplate DataType="{x:Type WakeUp:LocalWakeUpDestination}"/>
        
        <DataTemplate DataType="{x:Type WakeUp:ProxyWakeUpDestination}">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition SharedSizeGroup="Labels"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Label Grid.Column="0" Name="proxyLabel" Target="{Binding ElementName=proxyAddress}">
                    _Proxy (DNS or IP):
                </Label>
                <TextBox Grid.Column="1" Name="proxyAddress" Text="{Binding Path=ProxyAddress}"/>
            </Grid>
        </DataTemplate>
    </Page.Resources>
    <Grid Grid.IsSharedSizeScope="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition SharedSizeGroup="Labels" />
            <ColumnDefinition Width="*"/>
            <ColumnDefinition SharedSizeGroup="Buttons" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" MinHeight="30" />
            <RowDefinition Height="Auto" MinHeight="30" />
            <RowDefinition Height="Auto" MinHeight="30" />
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <Label Grid.Column="0" Grid.Row="0" Name="targetComputerLabel" Target="{Binding ElementName=targetComputer}">
            _Target:
        </Label>
        <ComboBox 
            Grid.Column="1" Grid.Row="0"
            Name="targetComputer"
            ItemsSource="{x:Static WakeUp:TargetComputer.All}"
            SelectedValuePath="Id"
            SelectedValue="{Binding Source={StaticResource Settings}, Path=Default.CurrentTarget, Mode=TwoWay}"
            DisplayMemberPath="Description"
            SelectionChanged="targetChanged"/>
        <Button Grid.Column="2" Grid.Row="0" Name="newTarget" Click="createNewTarget">
            New Target
        </Button>
        
        <Label Grid.Column="0" Grid.Row="1" Name="wakeUpDestinationLabel" Target="{Binding ElementName=wakeUpDestination}">
            _Destination:
        </Label>
        <ComboBox
            Grid.Column="1" Grid.Row="1"
            Name="wakeUpDestination"
            ItemsSource="{x:Static WakeUp:WakeUpDestination.All}"
            SelectedItem="{Binding ElementName=targetComputer, Path=SelectedItem.Destination}"
            DisplayMemberPath="Description"
            SelectionChanged="destinationChanged"/>
        <Button Grid.Column="2" Grid.Row="1" Name="newDestination" Click="createNewDestination">
            New Destination
        </Button>

        <Label Grid.Column="0" Grid.Row="2" Name="wakeUpMethodLabel" Target="{Binding ElementName=wakeUpMethod}">
            _Method:
        </Label>
        <ComboBox
            Grid.Column="1" Grid.Row="2"
            Name="wakeUpMethod"
            ItemsSource="{Binding ElementName=wakeUpDestination, Path=SelectedItem.Methods}"
            SelectedItem="{Binding ElementName=targetComputer, Path=SelectedItem.WakeUpMethod}"
            DisplayMemberPath="Description"/>

        <StackPanel Grid.Row="3" Grid.ColumnSpan="3" >
            <ContentPresenter Content="{Binding ElementName=targetComputer, Path=SelectedItem, Mode=OneWay}"/>
        </StackPanel>
    </Grid>
</Framework:PageViewBase>